#ifndef _FMVC_PARAMS_
#define _FMVC_PARAMS_

#include <string>

#include "QueryParams.h"

namespace FMVC
{  
  class Params
  {
    char** _envp;
    QueryParams* _postParams;
    QueryParams* _getParams;
    QueryParams* _cookieParams;
    public:
    Params(const FCGX_Request& request) : _envp(request.envp)
    {
      char *cLength = FCGX_GetParam("CONTENT_LENGTH",_envp);
      if (cLength != NULL)
      {
        int iLength = strtol(cLength, NULL, 10);
        std::stringstream rawData;

        for (int i = 0; i < iLength; ++i)
          rawData << (char)FCGX_GetChar(request.in);

        _postParams = new QueryParams(rawData.str());    
      }
      _getParams = new QueryParams(std::string(FCGX_GetParam("QUERY_STRING",_envp)));
      _cookieParams = new QueryParams(std::string(FCGX_GetParam("HTTP_COOKIE",_envp)));
    }

    std::string GetRequestUri() const
    {
      return std::string(FCGX_GetParam("REQUEST_URI",_envp));
    }

    std::string GetPostParam(const std::string &key) const
    {
      return _postParams->Get(key);
    };

    std::string GetGetParam(const std::string &key) const
    {
      return _getParams->Get(key);
    };

    std::string GetCookieParam(const std::string &key) const
    {
      return _cookieParams->Get(key);
    };

    ~Params()
    {
      delete _postParams;
      delete _getParams;
    };

  };
};
#endif
